﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Crypt_Tranceiver
{
    public partial class Form_login : Form
    {
        //public delegate void ChildClose();
        String path_program;
        String pass_file;
        String pass;


        public Form_login()
        {
            InitializeComponent();
            path_program = System.AppDomain.CurrentDomain.BaseDirectory;
            pass_file = path_program + "Password.txt";
            if (File.Exists(pass_file))
            {
                TextReader fin = new StreamReader(pass_file);
                pass = fin.ReadLine();
                fin.Close();
                if (pass.Length <= 0)
                {
                    TextWriter fout = new StreamWriter(File.Open(pass_file, FileMode.Truncate, FileAccess.Write));
                    fout.WriteLine("123456");
                    fout.Close();
                    pass = "123456";
                }
            }
            else
            {
                TextWriter fout = new StreamWriter(File.Open(pass_file, FileMode.OpenOrCreate, FileAccess.Write));
                fout.WriteLine("123456");
                fout.Close();
                pass = "123456";
            }
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (tb_pass.Text == pass)
            {
                this.Hide();
                Form_Main frm_main = new Form_Main();
                frm_main.close_father += this.Close;
                frm_main.Show();
            }
            else
            {
                MessageBox.Show("密码错误！");
            }
        }

        private void btn_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
